/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author KeaneDCunha
 */

import java.util.*;

public class Multicast {

    Vector queue = new Vector();
    Map<Int, Int> pidTimePair;
    LamportClock myClock = new LamportClock();
    
    public static void Broadcast(int pid, int timestamp, Vector queue)
    {
        NetworkPacket sendPacket = new NetworkPacket();
        sendPacket.setSrcInput(ClientSessionInput.REQUEST);

        Iterator queueIterator = queue.iterator();
        while(queueIterator.hasNext())
        {
            //send REQUEST message to all members of multicast group
            //send message using 'pid' and 'timestamp'
        }

        //To Do: need to WAIT for ALL replies
    }

    void ReceiveRequest(int pid, int timestamp)
    {
        //Not sure if I need to use this...wanted to pair together pid and corresponding timestamp
        pidTimePair.put(pid, timestamp);
        
        if(myClock.getValue() < timestamp)
        {
            //if myClock's value is less than received timestamp, I should go first --> put received on queue
            queue.add(pid);
        }
        else
        {
            //ToDo: send REPLY immediately
            NetworkPacket replyPacket = new NetworkPacket();
            //set Source fields & Dest. fields
            replyPacket.setSrcInput(ClientSessionInput.REPLY);
        }
        //if received REPLY from everybody
        //then execute
    }

    public static void ExitCS(int pid, int timestamp, Vector queue)
    {
        Broadcast(pid, timestamp, queue);
        queue.clear();
        
    }

}
